Implementing Further Features
Venn Diagrammer succeeds in its basic goal, which is to illustrate how to implement many of the essential user interface components of a typical Macintosh application and to introduce the very simplest features of the Operating System. It shows how to do basic drawing in a window and how to handle many user actions. Best of all, it's a real application that does useful, albeit limited, work.It's important to realize that although some parts of the source code presented throughout this book are purposely simplified, other parts are not. The code for handling dialog boxes, for instance, is designed to be easily amplified to handle other modeless dialog boxes. The basic event loop and the menu-handling code are also quite typical of what you'd find in a commercial Macintosh application. The Venn Diagrammer source code is not intended as a shell on which to base your application, but chances are you'll do at least a few things in the same way.
Still, the Venn Diagrammer source code fails to illustrate how to implement a number of important Macintosh features. Here's a moderately complete list of what's missing and where you can look to get the information you need to add these features to your application:
- Windows. The document windows created by the Venn Diagrammer application are of fixed size, so they don't need to contain zoom boxes, size boxes, or scroll bars. In all likelihood, however, your application will allow the user to enter and edit information (such as text or graphics) that will usually not fit in a fixed-size window. As a result, you will probably want to include support for these window elements. To learn how to handle zoom and size boxes, see the chapter "Window Manager" in Inside Macintosh: Macintosh Toolbox Essentials. To learn how to implement scroll bars, see the chapter "Control Manager" in that same book.
- Menus. The Macintosh system software provides support for several kinds of menus in addition to the standard "pull-down" menus used by the Venn Diagrammer application. A very useful adaptation of the pull-down menu is the pop-up menu, which you can put in dialog boxes and document windows. Moreover, both pop-up menus and pull-down menus can contain hierarchical menus, where an entire menu is attached to a menu item. For information about these additional kinds of menus, see the chapter "Menu Manager" in Inside Macintosh: Macintosh Toolbox Essentials. That chapter also shows how to modify a menu item's text and style, how to add a mark to a menu item, and how to associate an icon with a menu item. Because pop-up menus are actually very complex controls, you'll also need to read the chapter "Control Manager" in Inside Macintosh: Macintosh Toolbox Essentials to learn how to handle pop-up menus.
- Text. Most Macintosh applications support some form of text entry and editing, even if just to solicit some piece of information from the user in a dialog box. The system software includes TextEdit, which you can use to provide basic text-handling capabilities for your application. Although TextEdit was originally designed to handle edit fields in a dialog box, you can also use it for other purposes. For example, if you're writing a spreadsheet application, you might use TextEdit to handle small amounts of text. TextEdit is not, however, suitable for large amounts of text (greater than about 32,000 characters). If you're writing a word-processing application, you'll need to write your own custom text-handling routines. To learn how to handle text entry and editing in dialog boxes, see the chapter "Dialog Manager" in Inside Macintosh: Macintosh Toolbox Essentials. To learn how to use TextEdit directly, see the chapter "TextEdit" in Inside Macintosh: Text. This latter book also describes a number of other text-related facilities provided by the Macintosh system software, such as support for multiple fonts and non-Roman character sets.
- Files. The Venn Diagrammer application can create, read, and write resource files only (which contain the user's preferences). Most applications allow the user to create and edit information of arbitrary size, and they store that information in a file's data fork. The data fork can contain any kind of information you care to put there. You read and write data from a file's data fork using the File Manager, and you present the standard user interface for opening and saving files using the Standard File Package. The chapter "Introduction to File Management" in Inside Macintosh: Files shows how to use these and other services to implement the typical File menu commands (Open, Save, Save As, Revert, and so forth). Other chapters in that book provide more detailed information about the structure of the file system used on Macintosh computers and about the system software managers you can use to manipulate objects in the file system. For more complete information on reading and writing resource files, see the chapter "Resource Manager" in Inside Macintosh: More Macintosh Toolbox.
- Icons. To learn how to define icons for your application and its document files, see the chapter "Finder Interface" in Inside Macintosh: Macintosh Toolbox Essentials.
- Help. Every application should include the resources necessary to allow the Help Manager to display help balloons after the user has chosen the Show Balloons command from the Help menu. Usually you can add support for help balloons simply by adding resources to your application's resource fork, without having to change or recompile its source code. In some cases, however, you might also need to modify the source code to provide help balloons. For complete details on implementing help balloons, see the chapter "Help Manager" in Inside Macintosh: More Macintosh Toolbox.
- Printing. One of the easiest features to add to the Venn Diagrammer application is the capability to print a Venn diagram window. Printing essentially involves just drawing the window into a special graphics port called a printing graphics port. Before doing that, however, you need to present the standard dialog boxes to set up a page and to send a print job to a printer. If, as is usually the case, there are multiple pages to be printed, you'll want to structure your printing code into a printing loop. A complete printing loop is provided in the chapter "QuickDraw Printing Manager" in Inside Macintosh: Imaging. That chapter also shows how to handle a number of other printing-related tasks.
- Memory. The Venn Diagrammer application is surprisingly naive in its management of the memory in its own partition. For the most part, it simply tries to allocate the memory it needs for some particular operation, and if it fails to get that memory, it just does the safest thing it can to work around that failure. You'll want to implement a much more robust scheme to manage the memory you're allocated when your application starts up. You need to make sure that your application's memory requirements don't consume too much of your partition, because many system software routines (especially many QuickDraw routines) also use memory in your application partition. For a simple but effective memory-management strategy, see the chapter "Introduction to Memory Management" in Inside Macintosh: Memory. For some advice on how to segment your application's executable code to minimize its memory footprint, see the chapter "Segment Manager" in Inside Macintosh: Processes.
- Interapplication Communication. To take full advantage of the cooperative multitasking environment provided in system software versions 7.0 and later, your application should be able to communicate effectively with other open applications. The system software provides several ways in which you can interact with other applications. You can support the publish and subscribe capabilities of the Edition Manager (described earlier in "Interapplication Communication" beginning on page 14) and you can support high-level events such as Apple events. For complete details on how to communicate and share data with other applications, see the book Inside Macintosh: Interapplication Communication.
- Sound. You can enhance the perceived quality of your application by appropriately including sounds in its user interface. When, for example, the user asks the Venn Diagrammer application to check the user's diagram, the application might play some agreeable sound if the diagram is correct and some discordant sound otherwise. Sound can provide user feedback that is not achievable using text and graphics alone. Other applications are more directly involved with recording or producing sound. To learn how to add sound capabilities to your application, see the chapter "Introduction to Sound" in Inside Macintosh: Sound.
- Color. Like sound, color might be either an enhancement to or a fundamental feature of your application. For example, Venn Diagrammer might allow the user to fill empty regions with colored patterns. You can use QuickDraw to draw shapes, regions, and even text in any color supported by the available video devices. For complete information on supporting color in your application, see the appropriate chapters in Inside Macintosh: Imaging.
- IMPORTANT
- You don't have to read all of the books mentioned in this list to develop a Macintosh application. Which of the many Inside Macintosh books you'll need depends on the particular requirements of your application. (The Venn Diagrammer application, for instance, draws mainly on four books only: Inside Macintosh: Macintosh Toolbox Essentials, Inside Macintosh: More Macintosh Toolbox, Inside Macintosh: Memory, and Inside Macintosh: Imaging.) Moreover, you don't necessarily have to read all of a chapter to get started using a certain manager. Most chapters in Inside Macintosh contain advanced material that is likely to be of interest only to developers with very specialized needs.
![]()